<template>
    <div id="header" class="header">
        <div class="head-top">
            <div class="section">
                <div class="left-box">
                    <!-- <span>vue2.0单页应用</span> -->
                    <a target="_blank" href="#"></a>
                    <a target="_blank" href="#"></a>
                </div>
                <div id="menu" class="right-box">
                    <a href="/login" v-if="!ishow">登录</a>
                    <!-- <a href="/register">注册</a> -->
                    <!-- <span>登录</span> -->
                    <span @click="loginout" v-if="ishow">退出登录</span>
                    <strong>|</strong>
                    <a><i class="iconfont icon-phone"></i>联系我们</a>
                    <router-link :to="{ name: 'shopcart' }">
                        <i class="iconfont icon-cart"></i>
                        <span>购物车({{ $store.getters.total }})</span>
                    </router-link>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                ishow:true
            }
        },
        methods: {
            loginout(){
                this.$http.get(this.$api.logout).then(res => {
                    if(res.data.status == 0) {
                       this.$alert('成功退出', '提示')
                        this.ishow=false
                        this.$router.push({path: '/goods/list'});
                    }
                });
            },
            islogin(){
         this.$http.get(this.$api.isLogin).then(res => {
                    if(res.data.code == "nologin") {
                      this.ishow=false
                    }else{
                        this.ishow=true
                    }
                });
            }
        },
        created () {
            this.islogin()
        }
    }
</script>

<style scoped lang='less'>
#header{
   
    background-color: red;
}
</style>